using UnityEngine;
using UnityEngine.UI;

namespace HyuFrameWork
{
    public class TwinkleText : MonoBehaviour
    {
        public float maxA;
        public float minA;
        public float speed;

        private bool up = false;
        private Text text;

        private void Awake()
        {
            text = GetComponent<Text>();
        }

        private void Update()
        {
            var a = text.color.a;
            a = up ? a + speed * Time.deltaTime : a - speed * Time.deltaTime;
            if (!up && a <= minA)
            {
                a = minA;
                up = true;
            }
            else if (up && a >= maxA)
            {
                a = maxA;
                up = false;
            }
            text.color = text.color.NewColorA(a);
        }
    }
}
